#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 110;

int a[N], b[N];
int n;

void down(int u, int size) {
    int t = u;
    if (u * 2 <= size && b[t] < b[u * 2]) t = u * 2;
    if (u * 2 + 1 <= size && b[t] < b[u * 2 + 1]) t = u * 2 + 1;
    if (t != u) {
        swap(b[t], b[u]);
        down(t, size);
    }
}

inline void solution() {
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    for (int i = 1; i <= n; i ++ ) cin >> b[i];

    int p = 1;
    while (p <= n && b[p] >= b[p - 1]) p ++ ;
    int k = p;
    while (p <= n && b[p] == a[p]) p ++ ;
    if (p == n + 1) {
        cout << "Insertion Sort" << endl;
        sort(b + 1, b + k + 1);
    }
    else 
    {
        cout << "Heap Sort" << endl;
        p = n;
        while (b[1] <= b[p]) p -- ;
        swap(b[1], b[p]);
        down(1, p - 1);
    }

    cout << b[1];
    for (int i = 2; i <= n; i ++ ) cout << " " << b[i];
    cout << endl;

}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}